#include "Thread.hpp"

#include <unistd.h>
#include <time.h>
#include <stdlib.h>

#include <iostream>
#include <memory>

using std::cout;
using std::endl;
using std::unique_ptr;

class MyTask
{
public:
    void process()
    {
        //设置一个随机数的种子
        srand(time(nullptr));
        int cnt = 10;
        while(cnt-- > 0) {
            //获取一个100以内的随机数
            int number = rand() % 100;
            cout << "MyTask::process, produce a number: " << number << endl;
            sleep(1);
        }
    }
};

int main()
{
    MyTask task;
    //在构造函数中注册函数对象
    unique_ptr<wd::Thread>  thread(new wd::Thread(
            std::bind(&MyTask::process,&task)));
    thread->start();//开始运行子线程
    thread->join();//等待子线程运行结束
    printf("main thread is exiting\n");
    return 0;
}

